{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M_G-1ig6-__z"
      },
      "source": [
        "# LangChain Agent with PraisonAI\n",
        "This notebook demonstrates how to use LangChain-compatible tools and PraisonAI agents to research AI-related topics using Wikipedia and YouTube.\n",
        "\n",
        "---"
      ],
      "id": "M_G-1ig6-__z"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZVBvL3zK-__3"
      },
      "source": [
        "##  Dependencies"
      ],
      "id": "ZVBvL3zK-__3"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "d7aUlkgM-__5"
      },
      "outputs": [],
      "source": [
        "!pip install praisonaiagents langchain-community wikipedia youtube-search"
      ],
      "id": "d7aUlkgM-__5"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sHNzy00Q-__6"
      },
      "source": [
        "##  Set API Keys"
      ],
      "id": "sHNzy00Q-__6"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xCQvYxjK-__6"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "os.environ['OPENAI_API_KEY'] = 'your_api_key_here'"
      ],
      "id": "xCQvYxjK-__6"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1CDN1gXJ-__7"
      },
      "source": [
        "##  Tools and Agents Setup"
      ],
      "id": "1CDN1gXJ-__7"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "pj6Djfhd-__7"
      },
      "outputs": [],
      "source": [
        "from praisonaiagents import Agent, Task, PraisonAIAgents\n",
        "from langchain_community.utilities import WikipediaAPIWrapper\n",
        "from langchain_community.tools import YouTubeSearchTool\n",
        "\n",
        "wiki_agent = Agent(\n",
        "    name=\"WikiAgent\",\n",
        "    role=\"Research Assistant\",\n",
        "    goal=\"Search Wikipedia for accurate information\",\n",
        "    backstory=\"I am an AI assistant specialized in Wikipedia research\",\n",
        "    tools=[WikipediaAPIWrapper],\n",
        "    self_reflect=False\n",
        ")\n",
        "\n",
        "youtube_agent = Agent(\n",
        "    name=\"SearchAgent\",\n",
        "    role=\"Research Assistant\",\n",
        "    goal=\"Search for information from YouTube\",\n",
        "    backstory=\"I am an AI assistant that can search YouTube for relevant videos.\",\n",
        "    tools=[YouTubeSearchTool],\n",
        "    self_reflect=False\n",
        ")"
      ],
      "id": "pj6Djfhd-__7"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "X5YJSOPO-__8"
      },
      "source": [
        "##  Prompt and Tasks"
      ],
      "id": "X5YJSOPO-__8"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "dC2fi8ZF-__9"
      },
      "outputs": [],
      "source": [
        "task1 = Task(\n",
        "    name=\"wiki_task\",\n",
        "    description=\"Research 'Artificial Intelligence' on Wikipedia\",\n",
        "    expected_output=\"Comprehensive information from Wikipedia articles\",\n",
        "    agent=wiki_agent\n",
        ")\n",
        "\n",
        "task2 = Task(\n",
        "    name=\"search_task\",\n",
        "    description=\"Search for information about 'AI advancements' on YouTube\",\n",
        "    expected_output=\"Relevant information from YouTube videos\",\n",
        "    agent=youtube_agent\n",
        ")"
      ],
      "id": "dC2fi8ZF-__9"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YMFbVVTF-__-"
      },
      "source": [
        "##  Main Agent Execution"
      ],
      "id": "YMFbVVTF-__-"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "80jMkenz-__-"
      },
      "outputs": [],
      "source": [
        "agents = PraisonAIAgents(\n",
        "    agents=[wiki_agent, youtube_agent],\n",
        "    tasks=[task1, task2],\n",
        "    verbose=True\n",
        ")\n",
        "agents.start()"
      ],
      "id": "80jMkenz-__-"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "O13iiPNE-__-"
      },
      "source": [
        "#  LangChain Agent Outputs"
      ],
      "id": "O13iiPNE-__-"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6bL4CxKD-___"
      },
      "source": [
        "## 1. Wikipedia Agent Output\n",
        "\n",
        "### Artificial Intelligence (AI)\n",
        "\n",
        "Artificial intelligence (AI) refers to the capability of computational systems to perform tasks typically associated with human intelligence, such as learning, reasoning, problem-solving, perception, and decision-making. It is a field of research in computer science focused on developing methods and software that enable machines to perceive their environment and use learning and intelligence to take actions that maximize their chances of achieving defined goals.\n",
        "\n",
        "**Applications of AI:**\n",
        "- Advanced web search engines (e.g., Google Search)\n",
        "- Recommendation systems (e.g., YouTube, Amazon, Netflix)\n",
        "- Virtual assistants (e.g., Google Assistant, Siri, Alexa)\n",
        "- Autonomous vehicles (e.g., Waymo)\n",
        "- Generative and creative tools (e.g., ChatGPT, AI art)\n",
        "- Superhuman play and analysis in strategy games (e.g., chess, Go)\n",
        "\n",
        "**Subfields and Techniques:**\n",
        "AI research is centered around goals such as learning, reasoning, knowledge representation, planning, natural language processing, perception, and robotics support. Techniques include search and mathematical optimization, formal logic, artificial neural networks, and methods based on statistics, operations research, and economics. AI also draws from psychology, linguistics, philosophy, neuroscience, and other fields.\n",
        "\n",
        "**History and Development:**\n",
        "AI was founded as an academic discipline in 1956. The field has experienced cycles of optimism and disappointment, known as AI winters. Interest and funding increased significantly after 2012 with the use of graphics processing units to accelerate neural networks and the success of deep learning. The AI boom in the 2020s was marked by advanced generative AI, raising ethical concerns and discussions about regulatory policies.\n",
        "\n",
        "**Artificial General Intelligence (AGI):**\n",
        "AGI, or human-level intelligence AI, would match or surpass human capabilities across virtually all cognitive tasks. Some researchers believe that current large language models show early signs of AGI-level capability, while others argue that genuine AGI has not yet been achieved. AGI is distinct from artificial superintelligence (ASI), which would outperform human abilities across every domain. Unlike artificial narrow intelligence (ANI), AGI can generalize knowledge, transfer skills between domains, and solve novel problems without task-specific reprogramming.\n",
        "\n",
        "Creating AGI is a major goal for companies like OpenAI, Google DeepMind, and Meta, aiming to develop AI that can complete virtually any cognitive task as well as a human."
      ],
      "id": "6bL4CxKD-___"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lS0gvGjK-___"
      },
      "source": [
        "## 2. Web Search Agent Output\n",
        "\n",
        "### Latest AI Developments\n",
        "\n",
        "New Technologies in AI: Chatbots and Virtual Assistants are personalizing user experiences by analyzing user data and behavior, recommending products, content, and services, which increases engagement and sales."
      ],
      "id": "lS0gvGjK-___"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yJqv-2Vf-___"
      },
      "source": [
        "## 3. Agent Interaction Details\n",
        "\n",
        "**Wikipedia Agent Info:**  \n",
        "👤 Agent: WikiAgent  \n",
        "Role: Research Assistant  \n",
        "Tools: WikipediaAPIWrapper\n",
        "\n",
        "**Web Search Agent Info:**  \n",
        "👤 Agent: SearchAgent  \n",
        "Role: Research Assistant  \n",
        "Tools: YouTubeSearchTool\n",
        "\n",
        "**Performance Metrics:**\n",
        "- Wikipedia Agent Response Time: 15.4 seconds\n",
        "- Web Search Agent Response Time: 5.7 seconds"
      ],
      "id": "yJqv-2Vf-___"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Yv5abx7e-___"
      },
      "source": [
        "##  LangChain Tools with Wrappers"
      ],
      "id": "Yv5abx7e-___"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "3UywakPF-___"
      },
      "outputs": [],
      "source": [
        "!pip install langchain-community google-search-results"
      ],
      "id": "3UywakPF-___"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "otWS3SV0_AAA"
      },
      "outputs": [],
      "source": [
        "os.environ['SERPAPI_API_KEY'] = 'your_serpapi_key_here'"
      ],
      "id": "otWS3SV0_AAA"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "TE46xk8A_AAB"
      },
      "outputs": [],
      "source": [
        "from langchain_community.utilities import SerpAPIWrapper\n",
        "\n",
        "data_agent = Agent(\n",
        "    instructions=\"Search about AI job trends in 2025\",\n",
        "    tools=[SerpAPIWrapper]\n",
        ")\n",
        "editor_agent = Agent(instructions=\"Write a blog article\")\n",
        "\n",
        "agents = PraisonAIAgents(agents=[data_agent, editor_agent])\n",
        "agents.start()"
      ],
      "id": "TE46xk8A_AAB"
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2BqJBqaU_AAB"
      },
      "source": [
        "##  Example Without Wrapper (Brave Search)"
      ],
      "id": "2BqJBqaU_AAB"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "MxGyDSqY_AAC"
      },
      "outputs": [],
      "source": [
        "!pip install langchain-community"
      ],
      "id": "MxGyDSqY_AAC"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ZoD_erO__AAC"
      },
      "outputs": [],
      "source": [
        "os.environ['BRAVE_SEARCH_API'] = 'your_brave_api_key_here'"
      ],
      "id": "ZoD_erO__AAC"
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "-TQfJWzw_AAC"
      },
      "outputs": [],
      "source": [
        "from langchain_community.tools import BraveSearch\n",
        "\n",
        "def search_brave(query: str):\n",
        "    api_key = os.environ['BRAVE_SEARCH_API']\n",
        "    tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={\"count\": 3})\n",
        "    return tool.run(query)\n",
        "\n",
        "data_agent = Agent(instructions=\"Search about AI job trends in 2025\", tools=[search_brave])\n",
        "editor_agent = Agent(instructions=\"Write a blog article\")\n",
        "\n",
        "agents = PraisonAIAgents(agents=[data_agent, editor_agent])\n",
        "agents.start()"
      ],
      "id": "-TQfJWzw_AAC"
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}